import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: localStorage.token,
    shiname: localStorage.shiname,
    shiid: localStorage.shiid,
    quname: localStorage.quname,
    project: "阳光村(居)务监督平台",
    quid: "",
    id: Number(localStorage.id),
    zhenname: localStorage.zhenname,
    zhenid: localStorage.zhenid,
    cunname: localStorage.cunname,
    cunid: localStorage.cunid,
    name: localStorage.name,
    username: localStorage.username,
    userpassword: localStorage.userpassword,
    level: localStorage.level,
    //市管理员登录后保存的所有区的信息（区id和区name 每个区的镇id和镇name）
    district: {},

  },
  mutations: {
    setshiid(state,shiid){
      state.shiid = shiid;
      localStorage.shiid = shiid;
    },
    setshiname(state,shiname){
      state.shiname = shiname;
      localStorage.shiname = shiname;
    }
    ,genggaiquname (state, quname) {
      state.quname = quname
      localStorage.quname = quname
    },
    settoken(state, token) {
      state.token = token;
      localStorage.token = token;
    },
    setname(state, name) {
      state.name = name;
      localStorage.name = name;
    },
    setusername(state, username) {
      state.username = username;
      localStorage.username = username;
    },
    setuserpassword(state, userpassword) {
      state.userpassword = userpassword;
      localStorage.userpassword = userpassword;
    },
    // 设置管理员等级   0: 市   1：区    2：镇   3：村
    setlevel(state, level) {
      state.level = level;
      localStorage.level = level;
    },
    //设置用户id
    setid(state, id) {
      state.id = id;
      localStorage.id = id;
    },
    setzhenid(state, zhenid) {
      state.zhenid = zhenid;
      localStorage.zhenid = zhenid;
    },
    setzhenname(state, zhenname) {
      state.zhenname = zhenname;
      localStorage.zhenname = zhenname;
    },
    setcunname(state, cunname) {
      state.cunname = cunname;
      localStorage.cunname = cunname;
    },
    setcunid(state, cunid) {
      state.cunid = cunid;
      localStorage.cunid = cunid;
    },
    setdistrict(state, district) {
      state.district = district;
    },
  },
  getters: {
    gettoken: (state) => {
      return state.token;
    }
  },
  actions: {},
  modules: {}
})
